package cn.easyutil.util.platform.wechat.util;

import cn.easyutil.util.platform.base.PlatfromUserInfo;
import cn.easyutil.util.platform.wechat.base.WeChatLoginType;
import cn.easyutil.util.platform.wechat.base.WeChatMessage;
import cn.easyutil.util.platform.wechat.base.WeChatAccount;

/**
 * 微信平台操作
 */
public class WeChatOperation {

    private WeChatAccount account;

    private WeChatPublicOperation pOperation;

    private WeChatSmallAppOperation sOperation;

    private WeChatOperation(){}

    /**
     * 创建实例
     * @param account
     * @return
     */
    public static WeChatOperation build(WeChatAccount account){
        WeChatOperation operation = new WeChatOperation();
        WeChatPublicOperation publicOperation = new WeChatPublicOperation(account);
        WeChatSmallAppOperation smallAppOperation = new WeChatSmallAppOperation(account);
        operation.account = account;
        operation.pOperation = publicOperation;
        operation.sOperation = smallAppOperation;
        return operation;
    }
    /**
     * 创建实例
     * @param appid
     * @param appsecret
     * @return
     */
    public static WeChatOperation build(String appid,String appsecret){
        WeChatAccount account = new WeChatAccount();
        account.setAppid(appid);
        account.setAppsecret(appsecret);
        return build(account);
    }

    /**
     * 微信登陆
     * @param type
     * @param code
     * @return
     */
    public PlatfromUserInfo login(WeChatLoginType type,String code){
        switch (type){
            case thePublic:{
                return pOperation.login(code);
            }
            case web:{

            }
            case app:{

            }
            case smallApp:{
                return sOperation.login(code);
            }
        }
        return null;
    }

    /**
     * 通过公众号向用户发送通知
     * @param openId    用户唯一标识
     * @param templateId    通知模板id
     * @param message   通知内容
     * @return
     */
    public boolean pushMessage(String openId, String templateId, WeChatMessage message){
        return pOperation.pushMessage(openId,templateId,message);
    }

}
